package com.yvon.boot.mybatis.page;

import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
import com.google.common.base.Strings;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.reflection.property.PropertyNamer;

import java.io.Serializable;


@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SearchParam implements Serializable {
    private static final long serialVersionUID = 5094096637006312823L;
    @ApiModelProperty(value = "字段名")
    private String fieldName;

    @ApiModelProperty(value = "查询条件[eq-等于，ne-不等于，gt-大于，ge-大于等于，lt-小于，le-小于等于，between-范围，notBetween-不在范围，like-全模糊，notLike-非模糊，" +
            "orLike-多字段全模糊，likeLeft-前模糊，likeRight-后模糊，isNull-字段为null，isNotNull-字段不为null，in-结果集，notIn-非结果集]")
    private Operator operate;

    @ApiModelProperty(value = "值")
    private String value;

    @ApiModelProperty(value = "值1([between],[notBetween]范围查询时使用)")
    private String value1;

    private static String getColumn(String prefix, SerializedLambda lambda) {
        String name = PropertyNamer.methodToProperty(lambda.getImplMethodName());
        if (!Strings.isNullOrEmpty(prefix)) {
            name = prefix.concat(name);
        }

        return name;
    }


    public static enum Operator {
        eq,
        ne,
        gt,
        ge,
        lt,
        le,
        between,
        notBetween,
        like,
        notLike,
        orLike,
        likeLeft,
        likeRight,
        in,
        notIn,
        isNull,
        isNotNull;

        private Operator() {
        }
    }
}
